# 敌人角色类 - 继承自角色基类
class_name Enemy
extends Character

# 敌人特有属性
var enemy_type: String = "Normal"
var exp_reward: int = 10  # 击败后获得的经验值
var gold_reward: int = 5  # 击败后获得的金币
var loot_table: Array = []  # 掉落物品表
var ai_strategy: String = "normal"  # AI策略：normal, aggressive, defensive


# 初始化敌人角色
func _init(node_ref: Node2D, sprite_ref: Sprite2D = null, enemy_name: String = "Enemy"):
	super._init(node_ref, sprite_ref)
	name = enemy_name
	is_player = false


# 获取AI行动决策
func get_ai_action(battle_state: Dictionary) -> Dictionary:
	# 根据AI策略决定下一步行动
	match ai_strategy:
		"aggressive":
			return _get_aggressive_action(battle_state)
		"defensive":
			return _get_defensive_action(battle_state)
		"normal":
			# 默认为普通策略
			return _get_normal_action(battle_state)
		# 添加默认情况，确保所有代码路径都返回值
		_:
			return _get_normal_action(battle_state)


# 普通AI策略
func _get_normal_action(_battle_state: Dictionary) -> Dictionary:
	# 80%概率攻击，20%概率使用技能（如果有）
	if randi() % 10 < 8:
		return {"type": "attack"}
	# 这里可以添加敌人技能逻辑
	return {"type": "attack"}  # 暂时都返回攻击


# 激进AI策略
func _get_aggressive_action(_battle_state: Dictionary) -> Dictionary:
	# 总是攻击
	return {"type": "attack"}


# 防御AI策略
func _get_defensive_action(_battle_state: Dictionary) -> Dictionary:
	# 如果生命值低于30%，则尝试防御
	if current_hp < max_hp * 0.3:
		return {"type": "defend"}
	return {"type": "attack"}


# 生成掉落物品
func generate_loot() -> Array:
	var dropped_items = []

	# 根据战利品表生成掉落
	for loot in loot_table:
		var item = loot["item"]
		var drop_chance = loot["chance"]  # 0-1之间的概率

		if randf() < drop_chance:
			dropped_items.append(item)

	return dropped_items


# 敌人死亡时的额外处理
func on_death():
	super.on_death()
	# 可以添加敌人死亡的特效、动画等


# 重写获取状态信息的方法，添加敌人特有的信息
func get_status_info() -> Dictionary:
	var info = super.get_status_info()
	info["enemy_type"] = enemy_type
	info["exp_reward"] = exp_reward
	info["gold_reward"] = gold_reward
	info["ai_strategy"] = ai_strategy
	return info
